<?php


namespace app\api\controller\v12;


use app\api\controller\v2\Auth;
use app\common\cachemodel\ZlUserStarNumRecord;
use app\common\cachemodel\ZlUserVip;
use think\response\Json;

class User extends Auth
{
    /**
     * 准了号用户搜索
     * @return Json
     * @throws \Exception
     */
    public function uenSearch()
    {
        $uen = input('uen/s', '');

        if (empty($uen)) return show(config('code.error'), '用户不存在');

        $userInfo = (new \app\common\cachemodel\User())->uenSearch((int)$this->user['id'], $uen, 'avatar,nickname,id');

        if (empty($userInfo))
        {
            if ($uen === $this->user['uen'])
            {
                return show(config('code.error'), '优惠券不能赠送给自己');
            }

            return show(config('code.error'), '用户不存在');
        }
        // 获取VIP信息
        $userVip = (new ZlUserVip())->getInfoById($userInfo['id']);

        $data = [
            'avatar' => $userInfo['avatar'],
            'nickname' => $userInfo['nickname'],
            'vip' => (int)((empty($userVip) || $userVip['is_valid'] == 0) ? 0 : $userVip['vip_level'])
        ];

        return show(config('code.success'), '请求成功', $data);
    }

    /**
     * VIP星力值成长明细
     * @return Json
     * @throws \Exception
     */
    public function vipGrowRecord()
    {
        $type = input('type/d', 0);

        $data = (new ZlUserStarNumRecord())->getRecordList((int)$this->user['id'], $type);

        return show(config('code.success'), '请求成功', $data);
    }
}
